package com.andatsoft.laisim.dialog;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.andatsoft.laisim.R;
import com.andatsoft.laisim.theme.ThemeManager;

public class MessageBox extends FrameLayout {
	private Context mContext;
	private TextView mTextView;
	private TextView mTvOk;
	private TextView mTvCancel;

	public MessageBox(Context context) {
		super(context);
		this.mContext = context;
		initViews(false);
	}

	public MessageBox(Context context, boolean isAffectBySkin) {
		super(context);
		this.mContext = context;
		initViews(isAffectBySkin);
	}

	public MessageBox(Context context, AttributeSet attrs,
			boolean isAffectBySkin) {
		super(context, attrs);
		this.mContext = context;
		initViews(isAffectBySkin);
	}

	private void initViews(boolean isSkin) {
		LayoutInflater inflater = (LayoutInflater) mContext
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.dialog_message_confirm_background, this, true);

		inflater.inflate(R.layout.dialog_message_confirm, this, true);

		mTextView = (TextView) findViewById(R.id.tv_message_confirm_content);

		mTvOk = (TextView) findViewById(R.id.tv_message_confirm_ok);
		mTvCancel = (TextView) findViewById(R.id.tv_message_confirm_cancel);
		if (isSkin) {

			getBackgroundLayout().setBackgroundColor(
					ThemeManager.getSelectedTheme().getDialogBackgroundColor());
			getContent()
					.setBackgroundColor(
							ThemeManager.getSelectedTheme()
									.getDialogBackgroundColor() * 2);
			((TextView) findViewById(R.id.tv_title_message_confirm))
					.setTextColor(ThemeManager.getSelectedTheme()
							.getDialogTextColor());
			mTextView.setTextColor(ThemeManager.getSelectedTheme()
					.getDialogTextColor());
			mTvOk.setTextColor(ThemeManager.getSelectedTheme()
					.getDialogTextColor());
			mTvCancel.setTextColor(ThemeManager.getSelectedTheme()
					.getDialogTextColor());
		}
		// mContent.setPadding(80, 100, 20, 100);
		// addView(mBackground);
		// addView(mContent);
	}

	public void setMessageContent(String content) {
		if (mTextView == null)
			return;
		mTextView.setText(content);
	}

	public void setOkButtonOnTouchListener(OnTouchListener event) {
		if (mTvOk != null)
			mTvOk.setOnTouchListener(event);
	}

	public void setCancelButtonOnTouchListener(OnTouchListener event) {
		if (mTvCancel != null)
			mTvCancel.setOnTouchListener(event);
	}

	public LinearLayout getContent() {
		return (LinearLayout) getChildAt(1);
	}

	public LinearLayout getBackgroundLayout() {
		return (LinearLayout) getChildAt(0);
	}
}
